package com.xkdx.caipiao.my;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.xkdx.caipiao.LotteryHallActivity;
import com.xkdx.caipiao.R;
import com.xkdx.caipiao.ThreadActivity;
import com.xkdx.caipiao.fragment.UserInfoFragment;
import com.xkdx.caipiao.hall.ArrangeFiveActivity;
import com.xkdx.caipiao.hall.ArrangeThreeActivity;
import com.xkdx.caipiao.hall.BetFiveActivity;
import com.xkdx.caipiao.hall.BetLottoActivity;
import com.xkdx.caipiao.hall.BetSevenActivity;
import com.xkdx.caipiao.hall.BetThreeActivity;
import com.xkdx.caipiao.hall.LottoActivity;
import com.xkdx.caipiao.hall.SevenActivity;
import com.xkdx.caipiao.module.network.AbsModule;
import com.xkdx.caipiao.module.network.ErrorModule;
import com.xkdx.caipiao.presistence.faild.FaildAction;
import com.xkdx.caipiao.presistence.faild.FaildInfo;
import com.xkdx.caipiao.presistence.faild.FaildModule;
import com.xkdx.caipiao.presistence.faild.FaildPresistence;
import com.xkdx.caipiao.presistence.login.LoginInfo;
import com.xkdx.caipiao.presistence.quert.OrderDelAction;
import com.xkdx.caipiao.presistence.quert.OrderDelModule;
import com.xkdx.caipiao.presistence.quert.OrderDelPresistence;
import com.xkdx.caipiao.presistence.quert.OrderQueryAction;
import com.xkdx.caipiao.presistence.quert.OrderQueryItemInfo;
import com.xkdx.caipiao.presistence.quert.OrderQueryModule;
import com.xkdx.caipiao.presistence.quert.OrderQueryPresistence;
import com.xkdx.caipiao.pubclass.SelectCode;
import com.xkdx.caipiao.statics.IConstants;
import com.xkdx.caipiao.util.CaipiaoUtil;
import com.xkdx.caipiao.util.LinearLayoutForListView;
import com.xkdx.caipiao.util.Md5Utils;
import com.xkdx.caipiao.util.SharePrefenceUtil;

public class OrderDetailsActivity extends ThreadActivity {

	OrderQueryAction action;
	OrderQueryModule module;
	OrderQueryPresistence presistence;

	String orderid, id, lotteryName, status, tradestatus, ctime, moneyinfo,
			outtime, issurepay, ordertime, pid, groupid;
	float winnermoney = 0.0f;
	View view;

	List<OrderQueryItemInfo> list;
	OrderDelAction delAction;
	OrderDelModule delModule;
	OrderDelPresistence delPresistence;
	List<FaildInfo> list1;
	FaildAction faildAction;
	FaildModule faildModule;
	FaildPresistence faildPresistence;
	LinearLayoutForListView mylinearlayout ;
	ImageView back, arrow;

	TextView name, issue, pay, state, money, win_numbers_reds,
			win_nubers_blues, time, pay_order, del_order;
	TextView touzhu_num, touzhu_beishu;
	Button btn_continue, btn_bet, bt_hint;
	LinearLayout ll_sub;
	boolean isDelOrder = false;
	boolean isVisiable = false;
	boolean isFaild = false;
	private String redcode = "", bluecode = "";
	String type = "";
	private String simpname = "";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.order_details_caipiao);

		orderid = getIntent().getStringExtra("orderid");
		init();
		setClick();
		startThread();

	}

	@Override
	protected void onResume() {
		super.onResume();
		/*
		 * if(MyApplication.isDetails){ MyApplication.isDetails = false;
		 * finish(); }
		 */
	}

	private void setClick() {
		btn_continue.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {

				String btn_text = btn_continue.getText().toString();
				String str = simpname;
				Intent intent = null;
				Intent payIntent = null;
				String betting = "";
				if (str.equals("dlt")) {
					setCode(list, IConstants.list_selectcode);
					LotteryHallActivity.lotteryid = "dlt";
					if ("去支付".equals(btn_text)) {
						payIntent = new Intent(OrderDetailsActivity.this,
								OrderPayActivity.class);
						betting = CaipiaoUtil
								.getCaiPiaoString(IConstants.list_selectcode);
						payIntent.putExtra("betting", betting);
						payIntent.putExtra("money", moneyinfo);
						payIntent.putExtra("beishu", ordertime);
						payIntent.putExtra("issure", name.getText().toString()
								+ issue.getText().toString());
						payIntent.putExtra("pid", id);
						startActivity(payIntent);
					} else {
						intent = new Intent(OrderDetailsActivity.this,
								BetLottoActivity.class);
						startActivity(intent);
					}
				} else if (str.equals("qxc")) {
					LotteryHallActivity.lotteryid = "qxc";
					setCode(list, IConstants.list_sevencolor);
					if ("去支付".equals(btn_text)) {
						payIntent = new Intent(OrderDetailsActivity.this,
								OrderPayActivity.class);
						betting = CaipiaoUtil
								.getCaiPiaoString(IConstants.list_selectcode);
						payIntent.putExtra("betting", betting);
						payIntent.putExtra("money", moneyinfo);
						payIntent.putExtra("beishu", ordertime);
						payIntent.putExtra("issure", name.getText().toString()
								+ issue.getText().toString());
						payIntent.putExtra("pid", id);
						startActivity(payIntent);
					} else {
						intent = new Intent(OrderDetailsActivity.this,
								BetSevenActivity.class);
						startActivity(intent);
					}
				} else if (str.equals("pls")) {
					LotteryHallActivity.lotteryid = "pls";
					setCode(list, IConstants.list_three);
					if ("去支付".equals(btn_text)) {
						payIntent = new Intent(OrderDetailsActivity.this,
								OrderPayActivity.class);
						betting = CaipiaoUtil
								.getCaiPiaoString(IConstants.list_three);
						payIntent.putExtra("betting", betting);
						payIntent.putExtra("money", moneyinfo);
						payIntent.putExtra("beishu", ordertime);
						payIntent.putExtra("issure", name.getText().toString()
								+ issue.getText().toString());
						payIntent.putExtra("pid", id);
						startActivity(payIntent);
					} else {
						intent = new Intent(OrderDetailsActivity.this,
								BetThreeActivity.class);
						startActivity(intent);
					}
				} else if (str.equals("plw")) {
					LotteryHallActivity.lotteryid = "plw";
					setCode(list, IConstants.list_five);
					if ("去支付".equals(btn_text)) {
						payIntent = new Intent(OrderDetailsActivity.this,
								OrderPayActivity.class);
						betting = CaipiaoUtil
								.getCaiPiaoString(IConstants.list_five);
						payIntent.putExtra("betting", betting);
						payIntent.putExtra("money", moneyinfo);
						payIntent.putExtra("beishu", ordertime);
						payIntent.putExtra("issure", name.getText().toString()
								+ issue.getText().toString());
						payIntent.putExtra("pid", id);
						startActivity(payIntent);
					} else {
						intent = new Intent(OrderDetailsActivity.this,
								BetFiveActivity.class);
						startActivity(intent);
					}
				}

			}

		});
		btn_bet.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				String str = getLotteryIDFormLotteryName(lotteryName);
				Intent intent = null;
				if (str.equals("dlt")) {
					intent = new Intent(OrderDetailsActivity.this,
							LottoActivity.class);
				} else if (str.equals("qxc")) {
					intent = new Intent(OrderDetailsActivity.this,
							SevenActivity.class);
				} else if (str.equals("pls")) {
					intent = new Intent(OrderDetailsActivity.this,
							ArrangeThreeActivity.class);
				} else if (str.equals("plw")) {
					intent = new Intent(OrderDetailsActivity.this,
							ArrangeFiveActivity.class);
				}

				startActivity(intent);

			}
		});

		del_order.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				startDelThread();

			}
		});

		ll_sub.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (isVisiable) {
					isVisiable = false;
					arrow.setImageResource(R.drawable.down_arrow_more_caipiao);
					mylinearlayout.setVisibility(View.GONE);
				} else {
					isVisiable = true;
					arrow.setImageResource(R.drawable.up_arrow_more_caipiao);
					mylinearlayout.setVisibility(View.VISIBLE);
				}

			}
		});

	}

	private void init() {
		mylinearlayout = (LinearLayoutForListView) findViewById(R.id.subclass);
		ll_sub = (LinearLayout) findViewById(R.id.see_item_number);
		back = (ImageView) findViewById(R.id.back);
		del_order = (TextView) findViewById(R.id.del);

		name = (TextView) findViewById(R.id.name);
		issue = (TextView) findViewById(R.id.issue);
		pay = (TextView) findViewById(R.id.pay);
		state = (TextView) findViewById(R.id.state);
		money = (TextView) findViewById(R.id.money);
		win_numbers_reds = (TextView) findViewById(R.id.win_numbers_reds);
		win_nubers_blues = (TextView) findViewById(R.id.win_numbers_blues);
		touzhu_num = (TextView) findViewById(R.id.touzhu_num);
		touzhu_beishu = (TextView) findViewById(R.id.touzhu_beishu);
		touzhu_beishu.setVisibility(View.INVISIBLE);
		time = (TextView) findViewById(R.id.pay_time);
		pay_order = (TextView) findViewById(R.id.pay_order);
		btn_continue = (Button) findViewById(R.id.btn_continue);
		btn_bet = (Button) findViewById(R.id.double_bet);
		bt_hint = (Button) findViewById(R.id.bt_hint);

		arrow = (ImageView) findViewById(R.id.arrow);
		arrow.setImageResource(R.drawable.down_arrow_more_caipiao);
		// btn_bet.setText(lotteryName + "投注");
	}

	private void isShowDel_order() {
		if (outtime.equals("false")) {
			if (issurepay.equals("0")) {
				del_order.setVisibility(View.VISIBLE);
			} else {
				if (tradestatus.equals("3")) {
					if (status.equals("1") || status.equals("2")) {
						del_order.setVisibility(View.VISIBLE);
					}
				} else if ("4".equals(tradestatus)) {
					del_order.setVisibility(View.VISIBLE);
				} else {
					del_order.setVisibility(View.INVISIBLE);
				}
			}
		} else {
			del_order.setVisibility(View.VISIBLE);
		}
	}

	public void onBackClick(View view) {
		finish();
	}

	@Override
	public void showOnPost(HashMap<String, AbsModule> result) {
		if (dataLoadDialog.isShowing()) {
			dataLoadDialog.dismiss();
		}
		if (isFaild) {
			isFaild = false;
			if (result.containsKey("0")) {
				list1 = faildModule.list1;
				String str = "";
				for (int i = 0; i < list1.size(); i++) {
					String a = list1.get(i).getBetting();
					a = "\r\n" + a.replace(",", " :");
					str = str + a;
				}

				AlertDialog.Builder dialog = new Builder(
						OrderDetailsActivity.this);
				dialog.setTitle("失败列表");
				dialog.setMessage(str);

				dialog.setNegativeButton("取消",
						new android.content.DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								dialog.dismiss();
							}
						});

				dialog.setPositiveButton("重选",
						new android.content.DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface arg0, int arg1) {
								// TODO Auto-generated method stub
								arg0.dismiss();
								// 这里跳转到你想要去的页面
								String str = simpname;
								Intent intent = null;
								if (str.equals("dlt")) {
									setCode(list, IConstants.list_selectcode);
									LotteryHallActivity.lotteryid = "dlt";
									intent = new Intent(
											OrderDetailsActivity.this,
											BetLottoActivity.class);
									startActivity(intent);

								} else if (str.equals("qxc")) {
									LotteryHallActivity.lotteryid = "qxc";
									setCode(list, IConstants.list_sevencolor);

									intent = new Intent(
											OrderDetailsActivity.this,
											BetSevenActivity.class);
									startActivity(intent);

								} else if (str.equals("pls")) {
									LotteryHallActivity.lotteryid = "pls";
									setCode(list, IConstants.list_three);

									intent = new Intent(
											OrderDetailsActivity.this,
											BetThreeActivity.class);
									startActivity(intent);

								} else if (str.equals("plw")) {
									LotteryHallActivity.lotteryid = "plw";
									setCode(list, IConstants.list_five);

									intent = new Intent(
											OrderDetailsActivity.this,
											BetFiveActivity.class);
									startActivity(intent);

								}

							}

						});
				dialog.create().show();

			} else {
				toastErrorMessage(result);
			}

		}

		if (isDelOrder) {
			isDelOrder = false;
			if (result.containsKey("0")) {
				if (delModule.isSuccess) {
					finish();
					IConstants.localUserMoney = 0;
					UserInfoFragment.isUpdate = true;
				} else {
					toast("删除失败");
				}
			} else {
				toastErrorMessage(result);
			}
		} else {
			if (result.containsKey("0")) {

				if (module.info != null) {
					list = module.info.getList();
					int size = list.size();
					OrderQueryItemInfo item = list.get(0);
					setVarible(item); // 初始化变量
					setRedsOrBlues(item);

					isShowDel_order();
					btn_bet.setText(lotteryName + "投注");
					name.setText(lotteryName);
					pay.setText((moneyinfo + "元"));
					issue.setText(item.getIssueid() + "期");

					// 中奖金额
					for (int i = 0; i < size; i++) {
						winnermoney += Float.parseFloat(list.get(i)
								.getWinmoney());
					}
					winnermoney = winnermoney / 100;
					if (winnermoney == 0) {
						money.setText("---");
					} else {
						money.setText(winnermoney + "元");
					}

					touzhu_num.setText("共" + size + "条");
					time.setText("下单时间  " + ctime);

					pay_order.setText("订单编号  " + orderid);

					subAdatper adatper = new subAdatper(item);
					mylinearlayout.setAdapter(adatper);
				//	IConstants.setListViewHeightBasedOnChildren(listView);

				}

			} else {
				Toast.makeText(this,
						((ErrorModule) result.get("1")).errorMessage,
						Toast.LENGTH_SHORT).show();
			}
		}
	}

	private void setVarible(OrderQueryItemInfo item) {
		outtime = item.getOuttime();
		status = item.getStatus();
		tradestatus = item.getTradestatus();
		ctime = item.getCtime();
		// pid
		pid = item.getPid();
		groupid = item.getPid();

		moneyinfo = (Integer.parseInt(item.getOrderpaymoney()) + Integer
				.parseInt(item.getOrderpayRed())) / 100 + "";
		id = item.getPid();
		issurepay = item.getIssurepay();
		simpname = item.getLotteryid();
		if ("dlt".equals(simpname)) {
			lotteryName = "大乐透";
		} else if ("qxc".equals(simpname)) {
			lotteryName = "七星彩";
		} else if ("pls".equals(simpname)) {
			lotteryName = "排列三";
		} else {
			lotteryName = "排列五";
		}

		if (outtime.equals("false")) {
			if (issurepay.equals("0")) {
				state.setText("未支付");
			} else {
				if (tradestatus.equals("1")) {
					state.setText("出票中");
				} else if (tradestatus.equals("2")) {
					state.setText("出票中");
				} else if (tradestatus.equals("3")) {
					if (status.equals("0")) {
						state.setText("待开奖");
					} else if (status.equals("1")) {
						state.setText("未中奖");

					} else {
						state.setText("中奖");
					}
				} else if ("4".equals(tradestatus)) {
					state.setText("出票失败");
				} else {
					state.setText("部分出票失败");
				}
			}
		} else {
			state.setText("已过期");
		}
		String states = state.getText().toString();
		if ("未支付".equals(states)) {
			btn_continue.setText("去支付");
		}
		ordertime = item.getOrdertime();
		if ("部分出票失败".equals(states)) {
			bt_hint.setVisibility(View.VISIBLE);

			bt_hint.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View view) {
					startFalidThread();
				}

			});
		}

	}

	private void getResultSelectCode(String reds, String blues, String select,
			TextView tv) {

		SpannableStringBuilder style = new SpannableStringBuilder(select);
		if ("dlt".equals(type)) {

			String[] selfCode = select.trim().split("#");// 自己选号
			String[] winRed = reds.trim().split(" "); // 自己红色号码
			String[] winBlue = blues.trim().split(" "); // 自己蓝色号码

			for (int i = 0; i < winRed.length; i++) {
				if (selfCode[0].contains(winRed[i])) {
					int k = select.indexOf(winRed[i]);

					style.setSpan(new ForegroundColorSpan(Color.RED), k, k + 2,
							Spannable.SPAN_EXCLUSIVE_INCLUSIVE); // 设置指定位置文字的颜色

				}
			}

			if (!("".equals(blues))) {
				for (int j = 0; j < winBlue.length; j++) {
					if (selfCode[1].contains(winBlue[j])) {
						int kk = select.indexOf(winBlue[j]);
						style.setSpan(new ForegroundColorSpan(Color.BLUE), kk,
								kk + 2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE); // 设置指定位置文字的颜色
					}
				}
			}
		} else {
			if (!(select.contains("#"))) { // 单式
				String[] winRed = reds.trim().split(" ");
				String[] selfSelect = select.trim().split(" ");
				if (winRed.length == selfSelect.length) {
					for (int i = 0; i < winRed.length; i++) {
						if (winRed[i].trim().equals(selfSelect[i].trim())) {
							int k = select.trim().indexOf(selfSelect[i].trim());
							style.setSpan(new ForegroundColorSpan(Color.RED),
									k, k + 1,
									Spannable.SPAN_EXCLUSIVE_INCLUSIVE); // 设置指定位置文字的颜色
						}
					}
				}
			} else { // 复式 #分隔
				String[] winRed = reds.trim().split(" ");
				String[] selfSelect = select.trim().split("#");
				int pos = 0;
				for (int i = 0; i < winRed.length; i++) {
					if (i == 0) {
						pos = 0;
					} else {
						String[] count = selfSelect[i - 1].trim().split(" ");

						pos += (count.length - 1) * 2;
					}
					if (selfSelect[i].trim().contains(winRed[i].trim())) {
						String[] single = selfSelect[i].trim().split(" ");
						if (winRed[i].trim().equals(single[0])) {
							if (single.length == 1) {
								int k = pos + 4 * i;
								style.setSpan(
										new ForegroundColorSpan(Color.RED), k,
										k + 1,
										Spannable.SPAN_EXCLUSIVE_INCLUSIVE); // 设置指定位置文字的颜色
							}
						} else {
							pos = select.trim().indexOf(selfSelect[i].trim());
							for (int p = 0; p < single.length; p++) {
								if (winRed[i].trim().equals(single[p])) {
									int k = pos + p * 2;
									style.setSpan(new ForegroundColorSpan(
											Color.RED), k, k + 1,
											Spannable.SPAN_EXCLUSIVE_INCLUSIVE); // 设置指定位置文字的颜色
									break;
								}
							}
						}
					}

				}
			}
		}

		tv.setText(style);
	}

	public void onBackClick() {
		finish();
	}

	@Override
	public void startThread() {
		if (!(dataLoadDialog.isShowing())) {
			dataLoadDialog.show();
			dataLoadDialog.setContentView(R.layout.progressbar_caipiao);
		}
		SharePrefenceUtil su = new SharePrefenceUtil(this,
				SharePrefenceUtil.USERINFO);
		LoginInfo info = su.getUserInfo();
		String md5 = info.getId()+info.getLogintoken()+IConstants.key;
		String signcode = Md5Utils.md5(md5);
		action = new OrderQueryAction(info.getId(), info.getLogintoken(),
				orderid,signcode);
		module = new OrderQueryModule();
		presistence = new OrderQueryPresistence(this);
		presistence.setActitons(action);
		presistence.setModule(module);
		presistence.execute();

	}

	private void startDelThread() {
		if (!(dataLoadDialog.isShowing())) {
			dataLoadDialog.show();
			dataLoadDialog.setContentView(R.layout.progressbar_caipiao);
		}
		isDelOrder = true;
		LoginInfo info = getLoginInfo();
		String md5 = info.getId()+info.getLogintoken()+IConstants.key;
		String signcode = Md5Utils.md5(md5);
		delAction = new OrderDelAction(info.getId(), info.getLogintoken(), id,signcode);
		delModule = new OrderDelModule();
		delPresistence = new OrderDelPresistence(this);
		delPresistence.setActitons(delAction);
		delPresistence.setModule(delModule);
		delPresistence.execute();
	}

	private void startFalidThread() {
		if (!(dataLoadDialog.isShowing())) {
			dataLoadDialog.show();
			dataLoadDialog.setContentView(R.layout.progressbar_caipiao);
		}
		isFaild = true;
		SharePrefenceUtil su = new SharePrefenceUtil(this,
				SharePrefenceUtil.USERINFO);
		LoginInfo info = su.getUserInfo();
		String md5 = info.getId()+info.getLogintoken()+IConstants.key;
		String signcode = Md5Utils.md5(md5);
		faildAction = new FaildAction(info.getId(), info.getLogintoken(), pid,
				groupid,signcode);
		faildModule = new FaildModule();
		faildPresistence = new FaildPresistence(this);
		faildPresistence.setActitons(faildAction);
		faildPresistence.setModule(faildModule);
		faildPresistence.execute();
	}

	/**
	 * 向全局变量保存值
	 * 
	 * @param code
	 * @param list
	 */
	private void setCode(List<OrderQueryItemInfo> order_list,
			List<SelectCode> select_list) {
		select_list.clear();
		int size = order_list.size();
		if (size > 0) {
			for (int i = 0; i < size; i++) {
				SelectCode code = new SelectCode();
				String issuid = order_list.get(i).getLotteryid();
				String type = order_list.get(i).getType();
				if (issuid.equals("dlt")) {
					redcode = order_list.get(i).getBetting().split("#")[0]
							.replace(",", " ");
					bluecode = order_list.get(i).getBetting().split("#")[1]
							.replace(",", " ");
				} else {
					if ("1".equals(type)) {
						redcode = order_list.get(i).getBetting()
								.replace(",", " ");
					} else {
						redcode = order_list.get(i).getBetting()
								.replace("#", " ").replace(",", "");
					}
				}
				code.setRedCode(redcode + " ");
				code.setBlueCode(bluecode);
				code.setMoneyPerBet(Integer.parseInt(type) * 2 + "");
				code.setBettingNum(type + "");
				code.setMoneyPerBet("2");
				String singleOrDouble = "1".equals(type) ? "单式" : "复式";
				code.setSingleOrDouble(singleOrDouble);
				code.setBetMode(singleOrDouble + " 共" + type + "注"
						+ Integer.parseInt(type) * 2 + "元");
				select_list.add(code);
			}
		}

	}

	class subAdatper extends BaseAdapter {

		/**
		 * 修改
		 * 
		 * @param item
		 */
		private OrderQueryItemInfo item;
		private String[] strings;

		public subAdatper(OrderQueryItemInfo item) {
			this.item = item;
			strings = item.getOpennum().replace("#", ",").split(",");
		}

		@Override
		public int getCount() {
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			return list.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			Holder holder = null;
			if (convertView == null) {
				holder = new Holder();
				convertView = LayoutInflater.from(getApplicationContext())
						.inflate(R.layout.sub_bet_item_caipiao, null);
				holder.tv_red_number = (TextView) convertView
						.findViewById(R.id.sub_bet_red_number);
				holder.tv_blue_number = (TextView) convertView
						.findViewById(R.id.sub_bet_blue_number);
				holder.status = (TextView) convertView
						.findViewById(R.id.status);
				holder.type = (TextView) convertView.findViewById(R.id.type);
				convertView.setTag(holder);
			} else {
				holder = (Holder) convertView.getTag();
			}
			String type = list.get(position).getType();
			String ordertime = list.get(position).getOrdertime();

			String text = type.equals("1") ? "单式" : "复式";
			holder.type.setText(text + " " + ordertime + "倍");
			String classfica = list.get(position).getLotteryid();
			String code = list.get(position).getBetting();
			Log.i("xxxxx1", code);
			for (int i = 0; i < strings.length; i++) {
				Log.i("xxxxx2", strings[i]);
			}
			if (classfica.equals("dlt")) {
				StringBuilder builder = new StringBuilder();
				int index = code.indexOf("#");
				String prefixs = code.substring(0, index); // 前5位红球
				String[] prefix = prefixs.split(",");

				for (String p : prefix) {
					if (strings.length == 7
							&& Arrays.asList(Arrays.copyOfRange(strings, 0, 5))
									.contains(p))
						builder.append("<font color=red>" + p
								+ "</font>&nbsp;");
					else
						builder.append(p + "&nbsp;");
				}

				String subfixs = code.substring(index + 1);
				String[] subfixArr = subfixs.split(",");
				builder.append(" :  ");
				for (String subfix : subfixArr) {
					if (strings.length == 7
							&& Arrays.asList(Arrays.copyOfRange(strings, 5, 7))
									.contains(subfix))
						builder.append("<font color=blue>" + subfix
								+ "</font>&nbsp;");
					else
						builder.append(subfix + "&nbsp;");
				}
				Log.i("0000000000000", builder.toString());
				Log.i("1111111111111", strings.toString());
				holder.tv_red_number.setText(Html.fromHtml(builder.toString()));

			} else {

				if ("1".equals(type)) {
					// holder.tv_red_number.setText(code.replace(",", " : "));
					// 修改
					String str = code.replace("#", ",").replace(",", " ");
					String[] strs = str.split(" ");
					StringBuilder builder = new StringBuilder();
					for (int i = 0; i < strs.length; i++) {
						if (strings.length == strs.length
								&& !strs[i].equals(":")
								&& strs[i].equals(strings[i])) {
							builder.append("<font color=red>" + strs[i]
									+ "</font> &nbsp;");
						} else {
							builder.append(strs[i] + " &nbsp;");
						}
					}
					Log.i("22222222222", builder.toString());
					Log.i("333333333", strings.toString());
					holder.tv_red_number.setText(Html.fromHtml(builder
							.toString()));

				} else {
					// 修改复式排列三，复式分列问题
					String[] str_arr = code.split("#");
					StringBuilder builder = new StringBuilder();

					for (int i = 0; i < str_arr.length; i++) {
						String[] strs = str_arr[i].split(",");
						for (int j = 0; j < strs.length; j++) {
							if (strings.length == 7
									&& strs[j].equals(strings[i])) {
								builder.append("<font color=red>" + strs[j]
										+ "</font> &nbsp;");
							} else {
								builder.append(strs[j] + " &nbsp;");
							}
						}
						builder.append(" &nbsp;");
					}

					Log.i("44444444", builder.toString());
					Log.i("55555555", strings.toString());
					holder.tv_red_number.setText(Html.fromHtml(builder
							.toString()));
				}

			}

			return convertView;
		}

		/**
		 * 判断是否包含
		 * 
		 * @param strs
		 * @param str
		 * @return
		 */
		public boolean isContanie(String[] strs, String str) {
			for (int i = 0; i < strs.length; i++) {
				Log.i("===========", strs[i]);
				if (str.equals(strs[i])) {
					return true;
				}
			}
			return false;
		}

		class Holder {
			TextView tv_red_number, tv_blue_number, status, type;
		}
	}

	private void setRedsOrBlues(OrderQueryItemInfo item) {
		if (!item.getLotteryid().equals("dlt")) {
			if (!item.getOpennum().equals("")) {
				Log.e("xxxxxxxxxxxxxx", item.getOpennum().replace(",", " "));
				win_numbers_reds.setText(item.getOpennum().replace(",", " "));
			} else {
				win_numbers_reds.setText("等待开奖");
			}
		} else {

			String code = item.getOpennum();
			if (!code.equals("")) {
				if (code.contains("#")) {
					win_numbers_reds
							.setText(code.replace(",", " ").split("#")[0]);
					win_nubers_blues
							.setText(code.replace(",", " ").split("#")[1]);
				} else {
					win_numbers_reds.setText(code);
					win_nubers_blues.setText("");
				}
			} else {
				win_numbers_reds.setText("等待开奖");
			}
		}
	}

}
